package com.ruoyi.front.controller;

import com.ruoyi.admin.domain.ZhxTopic;
import com.ruoyi.admin.service.IZhxTopicService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 话题管理Controller
 * 
 * @author ruoyi
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/public/ZhxTopic")
public class PubZhxTopicController extends BaseController
{
    @Autowired
    private IZhxTopicService zhxTopicService;

    /**
     *√获取话题列表数量
     *√获取今日新增话题列表数量
     *√查询话题列表
     *√查询自己的话题列表
     *√新增话题
     *√删除话题
     *√修改话题
     */

    /**
     * 查询话题列表（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhxTopic zhxTopic)
    {
        startPage();
        List<ZhxTopic> list = zhxTopicService.selectZhxTopicList(zhxTopic);
        return getDataTable(list);
    }

    /**
     * 导出话题管理列表（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:export')")
    @Log(title = "话题管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZhxTopic zhxTopic)
    {
        List<ZhxTopic> list = zhxTopicService.selectZhxTopicList(zhxTopic);
        ExcelUtil<ZhxTopic> util = new ExcelUtil<ZhxTopic>(ZhxTopic.class);
        util.exportExcel(response, list, "话题管理数据");
    }

    /**
     * 获取话题管理详细信息（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:query')")
    @GetMapping(value = "/{topicId}")
    public AjaxResult getInfo(@PathVariable("topicId") Long topicId)
    {
        return success(zhxTopicService.selectZhxTopicByTopicId(topicId));
    }

    /**
     * 新增话题管理（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:add')")
    @Log(title = "话题管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhxTopic zhxTopic)
    {
        return toAjax(zhxTopicService.insertZhxTopic(zhxTopic));
    }

    /**
     * 修改话题管理（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:edit')")
    @Log(title = "话题管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhxTopic zhxTopic)
    {
        return toAjax(zhxTopicService.updateZhxTopic(zhxTopic));
    }

    /**
     * 删除话题管理（未使用）
     */
    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:remove')")
    @Log(title = "话题管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{topicIds}")
    public AjaxResult remove(@PathVariable Long[] topicIds)
    {
        return toAjax(zhxTopicService.deleteZhxTopicByTopicIds(topicIds));
    }



    /**
     * 获取作品列表
     */
    @GetMapping("/topicNum")
    public int getTopicNum()
    {
        return zhxTopicService.getTopicNum();
    }

    /**
     * 获取今日新增作品列表
     */
    @GetMapping("/topicNumToday")
    public int getTopicNumToday()
    {
        return zhxTopicService.getTopicNumToday();
    }


    /**
     * 查询话题列表
     * 根据点赞量(likeNum)从高到低排序
     */
//    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:list')")
    @GetMapping("/listByLike")
    public TableDataInfo listByLike(ZhxTopic zhxTopic)
    {
        startPage();
        List<ZhxTopic> list = zhxTopicService.selectZhxTopicListByLike(zhxTopic);
        return getDataTable(list);
    }

    /**
     * 查询自己的话题列表
     */
    @GetMapping("/listMine")
    public TableDataInfo listMine(ZhxTopic zhxTopic) {
        startPage();
        zhxTopic.setUserId(SecurityUtils.getUserId());
        List<ZhxTopic> list = zhxTopicService.selectZhxTopicList(zhxTopic);
        return getDataTable(list);
    }

    /**
     * 新增话题管理
     */
//    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:add')")
    @Log(title = "话题管理", businessType = BusinessType.INSERT)
    @PostMapping("/addTopic")
    public AjaxResult addTopic(@RequestBody ZhxTopic zhxTopic)
    {
        return toAjax(zhxTopicService.insertZhxTopic(zhxTopic));
    }

    /**
     * 修改话题管理
     */
//    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:edit')")
    @Log(title = "话题管理", businessType = BusinessType.UPDATE)
    @PutMapping("/editTopic")
    public AjaxResult editTopic(@RequestBody ZhxTopic zhxTopic)
    {
        return toAjax(zhxTopicService.updateZhxTopic(zhxTopic));
    }

    /**
     * 删除话题管理
     */
//    @PreAuthorize("@ss.hasPermi('ZhxAdmin:ZhxTopic:remove')")
    @Log(title = "话题管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeTopic/{topicIds}")
    public AjaxResult removeTopic(@PathVariable Long[] topicIds)
    {
        return toAjax(zhxTopicService.deleteZhxTopicByTopicIds(topicIds));
    }


}
